package com.dqhl.community.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.dqhl.community.R;
import com.dqhl.community.activity.ShoppingDetailActivity;
import com.dqhl.community.base.BaseMyAdapter;

/**
 * Created by LIENLIN on 2016/9/2.
 * 一个商家中各个特色商品
 */
public class ShoppingDetailAdapter extends BaseMyAdapter implements View.OnClickListener {

    private Button mBtnCollection;
    private ImageView mIvDetail;
    private int number=0;//商品数量

    public ShoppingDetailAdapter(Context context) {
        super(context);
    }

    @Override
    public int getCount() {
        return 6;
    }

    @Override
    public Object getItem(int i) {
        return number;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

//        number=0;
        final ViewHolder vh;
        if (view==null){
            vh=new ViewHolder();
            view= inflater.inflate(R.layout.shoppingdetail_lv_item,viewGroup,false);
            vh.mTvMoney= (TextView) view.findViewById(R.id.tv_shoppinig_moneynumber);
            vh.mTvNumber= (TextView) view.findViewById(R.id.tv_shopping_number);
            vh.mIvJian= (ImageView) view.findViewById(R.id.iv_shopping_jian);
            vh.mIvadd= (ImageView) view.findViewById(R.id.iv_shopping_jia);
            view.setTag(vh);
        }else {
            vh= (ViewHolder) view.getTag();

//            vh.num=0;
        }
        vh.mIvJian.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (vh.num>0){
                    number=--vh.num;
                    vh.mTvNumber.setText((vh.num)+"");
//                    vh.mTvMoney.setText("¥"+18.00*vh.num);
                    ((ShoppingDetailActivity)context).getMoney(-18);
                    if (vh.num==0){
                        vh.mIvJian.setVisibility(View.GONE);
                    }
                }
            }
        });
        vh.mIvadd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                number=++vh.num;

                ((ShoppingDetailActivity)context).getMoney(18);
                if (vh.num==1){
                    vh.mIvJian.setVisibility(View.VISIBLE);
                }
                vh.mTvNumber.setText(vh.num+"");
//                vh.mTvMoney.setText("¥"+18.00*vh.num);
            }
        });
        return view;
    }
    public class ViewHolder{
        public int num=0;//商品数量
        public ImageView mIvadd,mIvJian;
        public TextView mTvNumber,mTvMoney;
    }



    @Override
    public void onClick(View view) {

        switch (view.getId()){

        }
    }
}
